using System;
using System.Linq;
using FluentNHibernate.Conventions.Instances;

namespace Caramel.FluentNHibernate.Conventions
{
	public class NotNullConvention : global::FluentNHibernate.Conventions.IPropertyConvention
	{
		public NotNullConvention(string name)
			: this(name, StringComparison.InvariantCultureIgnoreCase)
		{
		}

		public NotNullConvention(string name, StringComparison comparisonType)
		{
			this.Name = name;
			this.ComparisonType = comparisonType;
		}

		public string Name { get; private set; }

		public StringComparison ComparisonType { get; private set; }

		public void Apply(IPropertyInstance instance)
		{
			if (instance.Name.Equals(this.Name, this.ComparisonType))
			{
				instance.
					Not.
					Nullable();
			}

			//var fields =
			//    new string[] 
			//    {
			//        "Created",
			//        "CreatedBy",
			//        "Updated",
			//        "UpdatedBy"
			//    };

			//var name = instance.Name;

			//if (fields.Contains(name))
			//{
			//    return;
			//}


		}
	}
}
